package gov.goias.recad.persistencia;

import gov.goias.recad.dominio.Servidor;
import gov.goias.recad.excessao.InfraExcessao;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

@Repository
public class ServidorDAO{
	
	@PersistenceContext
	protected EntityManager persistencia;
	
	public Servidor obterPorCPF(final Long cpf)throws InfraExcessao{
		Servidor retorno = null;
		
		final Query consulta =  persistencia.createQuery("from Servidor where cpf = :cpf");		
		consulta.setParameter("cpf", cpf);
		
		try{
			retorno =  (Servidor) consulta.getSingleResult();	
		}catch(NoResultException e){
			retorno = null;
		}
		
		return retorno;
	}
	
	
}